package cheme.ProcessModel.Cmds;

import java.util.List;

import org.eclipse.gef.commands.Command;

import cheme.ProcessModel.IChild;
import cheme.ProcessModel.IParent;


public class OrphanChildCmd extends Command
{
	protected IParent parent;
	protected IChild child;

	protected int index;

	public OrphanChildCmd(IChild child)
	{
		super("Orphan Child Command");
		
		this.child = child;
	}
	
	protected void preExecute()
	{
		parent = child.getParent();
		
		List children = parent.getChildren();
		index = children.indexOf(child);
	}

	public void execute()
	{
		preExecute();
		
		parent.remove(child);
	}

	public void redo()
	{
		parent.remove(child);
	}

	public void undo()
	{
		parent.add(child, index);
	}
}